import posts from '../utils/postData.js';

export const createPostItems = (postList) => {
  posts.forEach((post) => {
    const postItem = document.createElement('div');
    postItem.classList.add('post-item');
    postItem.dataset.postId = post.id;

    const postCover = document.createElement('div');
    postCover.classList.add('post-cover');
    const coverImg = document.createElement('img');
    coverImg.src = post.coverImage;
    coverImg.alt = post.title;
    postCover.appendChild(coverImg);

    const postInfo = document.createElement('div');
    postInfo.classList.add('post-info');

    const title = document.createElement('p');
    title.textContent = post.title;

    const meta = document.createElement('p');
    meta.textContent = `发表于${post.publishDate} | 最后修改于${post.modifyDate} | ${post.category}`;

    const tag = document.createElement('p');
    tag.textContent = post.tags;

    postInfo.appendChild(title);
    postInfo.appendChild(meta);
    postInfo.appendChild(tag);

    postItem.appendChild(postCover);
    postItem.appendChild(postInfo);

    postList.appendChild(postItem);
  });
};
